<template>
  <div>
    <!-- <a-row>
      <a-col :span="20">
        <a-select
          ref=""
          :style="{ width: '100%' }"
          placeholder="客户选择"
          disabled
          v-model="curValue"
          @search="handleSearch"
          :allowClear="true"
          :showSearch="true"
          :filterOption="false"
          @change="changeuser"
        >
          <a-select-option v-for="(item, index) in dataSource" :key="index" :value="item"
            >{{ item.cCusName }}
          </a-select-option>
        </a-select>
      </a-col>
      <a-col :span="4">
        <a-button type="primary" :disabled="disabled" @click="handleOpenChoose" style="padding: 0 5px;width: 65px">
          <a-icon type="search" />
        </a-button>
      </a-col>
    </a-row> -->
    <a-input disabled v-model="curValue" placeholder="客户选择" style="width:calc(100% - 60px);;  max-height: 32px"> </a-input>
    <a-button :disabled="disabled" @click="handleOpenChoose" style="width:60px" type="primary">
      <a-icon class="colour" type="search" />
    </a-button>
    <ListChoose ref="supplierChoose" @onChoose="handleChoose"></ListChoose>
  </div>
</template>
<script>
import ListChoose from './ListChoose.vue'

export default {
  props: {
    value: { type: [String, Object], required: false },
    disabled: { type: Boolean, required: false, default: false }
  },
  components: {
    ListChoose
  },
  data() {
    return {
      curValue: '',
      keyword: '',
      RealName: '',
      timeout: null,
      dataSource: []
    }
  },
  watch: {
    value(value) {
      this.curValue = value
      //console.log(value)
      if (this.dataSource.length === 0) {
        if (value) {
          this.dataSource = [...value]
        } else {
          this.dataSource = []
          //console.log(this.dataSource, value, '错误')
        }
      }
    },
    curValue(n, o) {
      //console.log(n, o)
      if (n) {
        //console.log(this.$parent)
      }
    }
  },
  mounted() {
    this.curValue = this.value
  },
  methods: {
    changeuser() {
      //console.log(124)
    },
    handleSearch(value) {
      this.reload(value)
      //console.log(123)
    },
    handleOpenChoose() {
      this.$refs.supplierChoose.openChoose()
    },
    handleChoose(selectedRows) {
      //console.log(selectedRows)

      // this.$http
      //   .post(
      //     '/CustomerManagement/Cust_CustomerAllocation/GetUserInfoByCustomerId?CustomerId=' + selectedRows[0].cCusCode
      //   )
      //   .then(resJson => {
      //     //console.log('res', resJson)
      //     this.RealName = resJson.Data.RealName
      //     //console.log(this.RealName)
      //   })

      this.$emit('onname', this.RealName)
      this.dataSource = [...selectedRows]
      var row = selectedRows[0]
      this.curValue = selectedRows.cCusName
      this.$emit('input', this.curValue)
      this.$emit('closeMode', row)
    }
  }
}
</script>
